Bug 38137

Bug Description:

This is a starvation bug caused by improper use of wait() and notify() in a consumer and producer pattern. The following thread dump shows the starvation situation: both consumer,"Dispatcher-Thread-0", and producers, "Thread-*" are in waiting state:

"Thread-3" prio=6 tid=0x000000000d362000 nid=0x25c0 in Object.wait() [0x00000000
0e01f000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000007d5e3bf88> (a org.apache.log4j.helpers.BoundedFIFO)
at java.lang.Object.wait(Object.java:503)
at org.apache.log4j.AsyncAppender.append(AsyncAppender.java:104)
- locked <0x00000007d5e3bf88> (a org.apache.log4j.helpers.BoundedFIFO)
at org.apache.log4j.Test38137$AppendThread.run(Test38137.java:62)

"Thread-1" prio=6 tid=0x000000000d35a800 nid=0x148c in Object.wait() [0x00000000
0de1f000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000007d5e3bf88> (a org.apache.log4j.helpers.BoundedFIFO)
at java.lang.Object.wait(Object.java:503)
at org.apache.log4j.AsyncAppender.append(AsyncAppender.java:104)
- locked <0x00000007d5e3bf88> (a org.apache.log4j.helpers.BoundedFIFO)
at org.apache.log4j.Test38137$AppendThread.run(Test38137.java:62)

"Dispatcher-Thread-0" daemon prio=2 tid=0x000000000d359800 nid=0x1f94 in Object.
wait() [0x000000000dd1f000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000007d5e3bf88> (a org.apache.log4j.helpers.BoundedFIFO)
at java.lang.Object.wait(Object.java:503)
at org.apache.log4j.Dispatcher.run(AsyncAppender.java:312)
- locked <0x00000007d5e3bf88> (a org.apache.log4j.helpers.BoundedFIFO)
More details about this bug are at LOG4J-38137 JIRA page.

How To Reproduce:

This bug is reproduced under log4j 1.2.13 and JDK 1.6.0_33.
Execute the following scripts to run the test to reproduce the bug (assume the location of the log4j test project is log4j_test_home).

Linux:
${log4j_test_home}/scripts/38137.sh [--monitoroff]
Windows:
%log4j_test_home%\scripts\38137.bat [--monitoroff]

Example: Use monitor to report and terminate the program when forever waiting happens:
${log4j_test_home}/scripts/38137.sh


Turn off monitor:
${log4j_test_home}/scripts/38137.sh --monitoroff

Option Function
--monitoroff, -mo Turn off to stop reporting bug messages and ending program when test
runs into the expected concurrency bug which is a forever waiting.
User has to terminate the program manually when this option is set.